#ifndef __SUBSYSTEM_COLLAPSING_BLOCK_BEHAVIOR_BASE_H__
#define __SUBSYSTEM_COLLAPSING_BLOCK_BEHAVIOR_BASE_H__

#include "Subsystems/BlockBehaviors/SubsystemBlockBehavior.hpp"
#include "GameRandom.hpp"
#include "Engine/Point3.hpp"
#include "Game/MovingBlock.h"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class SubsystemTerrain;
    class SubsystemGameInfo;
    class SubsystemMovingBlocks;

    class SubsystemCollapsingBlockBehavior : public SubsystemBlockBehavior
    {
    public:
        SubsystemTerrain *m_terrain;
        SubsystemGameInfo *m_gameInfo;
        SubsystemMovingBlocks *m_movingBlocks;

    protected:
        void movingBlocksCollidedWithTerrain(MovingBlockSet *movingBlockSet, const Point3 &p);
        void movingBlocksStopped(MovingBlockSet *movingBlockSet);
        void tryCollapseColumn(const Point3 &p);

        bool isCollapsibleBlock(int32_t value);
        bool isCollapseSupportBlock(int32_t value);
        bool isCollapseDestructibleBlock(int32_t value);

    public:
        SubsystemCollapsingBlockBehavior();

        virtual void onNeighborBlockChanged(int32_t x, int32_t y, int32_t z, int32_t neighborX, int32_t neighborY, int32_t neighborZ) override;

        virtual void load(const nlohmann::json &json) override;
        virtual const std::string& getName() const override;
    };
}

#endif
